import Vue from 'vue'
import Router from 'vue-router'

// 路由按需加载
const Index = r => require.ensure([], () => r(require('@/components/Index')), 'Index')
const Seckill = r => require.ensure([], () => r(require('@/components/Seckill')), 'Seckill')
const Search = r => require.ensure([], () => r(require('@/components/Search')), 'Search')
const Category = r => require.ensure([], () => r(require('@/components/Category')), 'Category')
const ShopCart = r => require.ensure([], () => r(require('@/components/ShopCart')), 'ShopCart')
const My = r => require.ensure([], () => r(require('@/components/my/My')), 'My')
const UserInfo = r => require.ensure([], () => r(require('@/components/my/UserInfo')), 'UserInfo')
const MyOrder = r => require.ensure([], () => r(require('@/components/my/MyOrder')), 'MyOrder')
const OrderDetail = r => require.ensure([], () => r(require('@/components/my/OrderDetail')), 'OrderDetail')
const MyCollect = r => require.ensure([], () => r(require('@/components/my/MyCollect')), 'MyCollect')
const browseHistory = r => require.ensure([], () => r(require('@/components/my/browseHistory')), 'browseHistory') 
const MyAddress = r => require.ensure([], () => r(require('@/components/my/MyAddress')), 'MyAddress')
const MyAssess = r => require.ensure([], () => r(require('@/components/my/MyAssess')), 'MyAssess')
const MyMessage = r => require.ensure([], () => r(require('@/components/my/MyMessage')), 'MyMessage')
const MessageDetail = r => require.ensure([], () => r(require('@/components/my/MessageDetail')), 'MessageDetail')
const EditAddress = r => require.ensure([], () => r(require('@/components/my/EditAddress')), 'EditAddress')
const MyDistribut = r => require.ensure([], () => r(require('@/components/my/MyDistribut')), 'MyDistribut')
const GoodsList = r => require.ensure([], () => r(require('@/components/goods/GoodsList')), 'GoodsList')
const GoodsDetail = r => require.ensure([], () => r(require('@/components/goods/GoodsDetail')), 'GoodsDetail')
const Login = r => require.ensure([], () => r(require('@/components/Login')), 'Login')
const Register = r => require.ensure([], () => r(require('@/components/Register')), 'Register')
const ForgotPassword = r => require.ensure([], () => r(require('@/components/ForgotPassword')), 'ForgotPassword')
const BuyConfirm = r => require.ensure([], () => r(require('@/components/BuyConfirm')), 'BuyConfirm')
const ExpressInfo = r => require.ensure([], () => r(require('@/components/my/ExpressInfo')), 'ExpressInfo')
const PublishComment = r => require.ensure([], () => r(require('@/components/my/PublishComment')), 'PublishComment')


Vue.use(Router)
export default new Router({
  scrollBehavior (to, from, savedPosition) {
    return { y: 0 }
  },
  routes: [
    {
      path: '/',
      name: 'Index',
      component: Index,
      meta: {
        title: '首页'
      }
    },
    {
      path: '/seckill',
      name: 'Seckill',
      component: Seckill,
      meta: {
        title: '限时秒杀'
      }
    },
    {
      path: '/search',
      name: 'Search',
      component: Search,
      meta: {
        title: '搜索'
      }
    },
    {
      path: '/category',
      name: 'Category',
      component: Category,
      meta: {
        title: '全部分类'
      }
    },
    {
      path: '/cart',
      name: 'ShopCart',
      component: ShopCart,
      meta: {
        title: '购物车'
      }
    },
    {
      path: '/my',
      name: 'My',
      meta: {
        requireAuth: true,
        title: '我的' 
      },
      component: My
    },
    {
      path: '/my/userInfo',
      name: 'UserInfo',
      meta: {
        requireAuth: true,
        title: '个人资料'
      },
      component: UserInfo
    },
    {
      path: '/my/message',
      name: 'MyMessage',
      meta: {
        requireAuth: true,
        title: '我的消息' 
      },
      component: MyMessage
    },
    {
      path: '/my/message/detail',
      name: 'MessageDetail',
      component: MessageDetail,
      meta: {
        requireAuth: true,
        title: '消息详情' 
      },
    },
    {
      path: '/my/collect',
      name: 'MyCollect',
      meta: {
        requireAuth: true,
        title: '我的收藏' 
      },
      component: MyCollect
    },
    {
      path: '/my/assess',
      name: 'MyAssess',
      meta: {
        requireAuth: true,
        title: '我的评价' 
      },
      component: MyAssess
    },
    {
      path: '/my/history',
      name: 'browseHistory',
      meta: {
        requireAuth: true,
        title: '浏览历史' 
      },
      component: browseHistory
    },
    {
      path: '/my/address',
      name: 'MyAddress',
      meta: {
        requireAuth: true,
        title: '地址管理' 
      },
      component: MyAddress
    },
    {
      path: '/my/address/:type',
      name: 'EditAddress',
      component: EditAddress,
      meta: {
        requireAuth: true,
        title: '地址管理' 
      }
    },
    {
      path: '/my/order',
      name: 'MyOrder',
      component: MyOrder,
      meta: {
        requireAuth: true,
        title: '我的订单' 
      }
    },
    {
      path: '/my/order/detail',
      name: 'OrderDetail',
      component: OrderDetail,
      meta: {
        requireAuth: true,
        title: '订单详情' 
      },
    },
    {
      path: '/goods',
      name: 'GoodsList',
      component: GoodsList,
      meta: {
        title: '商品列表' 
      },
    },
    {
      path: '/goods/detail',
      name: 'GoodsDetail',
      component: GoodsDetail,
      meta: {
        title: '商品详情'
      }
    },
    {
      path: '/login',
      name: 'Login',
      component: Login,
      meta: {
        title: '登录'
      }
    },
    {
      path: '/register',
      name: 'Register',
      component: Register,
      meta: {
        title: '注册'
      }
    },
    {
      path: '/forgotpassword',
      name: 'ForgotPassword',
      component: ForgotPassword,
      meta: {
        title: '忘记密码'
      }
    },
    {
      path: '/order/buyConfirm',
      name: 'BuyConfirm',
      component: BuyConfirm,
      meta: {
        title: '购买确认'
      }
    },
    {
      path: '/order/expressInfo',
      name: 'ExpressInfo',
      component: ExpressInfo,
      meta: {
        title: '物流信息'
      }
    },
    {
      path: '/order/publishComment',
      name: 'PublishComment',
      component: PublishComment,
      meta: {
        title: '发表评价'
      }
    }
  ]
})
